a11y: Add more accessible data to GtkTreeExpander
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 12 Nov 2020 16:16:48 +0000 (16:16 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Thu, 12 Nov 2020 21:46:06 +0000 (21:46 +0000)
Document the role of the GtkTreeExpander, and the behaviour of the
expander button.

Additionally, improve the label of the expander button, by adding a
fixed "Expand" label, and setting the "labelled-by" relation to the
child of the GtkTreeExpander.

gtk/gtktreeexpander.c

index 2a68df898d7215f1174da73254329c3f3075903a..9b50e02039add4777784123bbc3a419e3b77355a 100644 (file)
@@ -25,6 +25,7 @@
 #include "gtkboxlayout.h"
 #include "gtkbuiltiniconprivate.h"
 #include "gtkdropcontrollermotion.h"
+#include "gtkenums.h"
 #include "gtkgestureclick.h"
 #include "gtkintl.h"
 #include "gtktreelistmodel.h"
  * If the node is not expandable, an "indent" node will be displayed instead.
  *
  * For every level of depth, another "indent" node is prepended.
+ *
+ * # Accessibility
+ *
+ * GtkTreeExpander uses the %GTK_ACCESSIBLE_ROLE_GROUP role. The expander icon
+ * is represented as a %GTK_ACCESSIBLE_ROLE_BUTTON, labelled by the expander's
+ * child, and toggling it will change the %GTK_ACCESSIBLE_STATE_EXPANDED state.
  */
 
 struct _GtkTreeExpander
@@ -182,6 +189,13 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
               gtk_widget_insert_before (self->expander,
                                         GTK_WIDGET (self),
                                         self->child);
+
+              gtk_accessible_update_property (GTK_ACCESSIBLE (self->expander),
+                                              GTK_ACCESSIBLE_PROPERTY_LABEL, _("Expand"),
+                                              -1);
+              gtk_accessible_update_relation (GTK_ACCESSIBLE (self->expander),
+                                              GTK_ACCESSIBLE_RELATION_LABELLED_BY, self->child, NULL,
+                                              -1);
             }
 
           if (gtk_tree_list_row_get_expanded (self->list_row))
@@ -600,6 +614,7 @@ gtk_tree_expander_class_init (GtkTreeExpanderClass *klass)
 
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, I_("treeexpander"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP);
 }
 
 static gboolean